package com.laijiale.controller;

import com.laijiale.constant.ML;
import com.laijiale.dto.EpisodeExcelDTO;
import com.laijiale.dto.EpisodeInsertDTO;
import com.laijiale.dto.EpisodePageDTO;
import com.laijiale.dto.EpisodeUpdateDTO;
import com.laijiale.entity.Episode;
import com.laijiale.result.Result;
import com.laijiale.service.EpisodeService;
import com.laijiale.until.EasyExcelUtil;
import com.mybatisflex.core.paginate.Page;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.laijiale.entity.Episode;
import com.laijiale.service.EpisodeService;
import org.springframework.web.multipart.MultipartFile;
import vo.EpisodeSimpleListVO;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 集次表 控制层。
 *
 * @author laijiale
 * @since 2024-12-22
 */
@RestController
@RequestMapping("/episode")
public class EpisodeController {

    @Autowired
    private EpisodeService episodeService;


    @Operation(summary ="新增－ 单条",description ="新增一条集次记录")
    @PostMapping("insert")
    public boolean insert(@Validated @RequestBody EpisodeInsertDTO dto) {
        return episodeService.insert(dto);
    }
    @Operation(summary="查询－ 单条",description="按主键查询一条集次记录")
    @GetMapping("select/{id}")
    public Episode select(@PathVariable("id") Long id) {
        return episodeService.select(id);
    }
    @Operation(summary ="查询－ 简单全查",description="查询全部集次记录")
    @GetMapping("simpleList")
    public List<EpisodeSimpleListVO> simpleList() {
        return episodeService.simpleList();
    }
    @Operation(summary="查询－ 分页",description ="分页查询集次记录")
    @GetMapping("page")
    public Page<Episode> page(@Validated EpisodePageDTO dto) {
        return episodeService.page(dto);
    }

    @Operation(summary="修改－单条",description ="按主键修改一条集次记录")
    @PutMapping("update")
    public boolean update(@RequestBody EpisodeUpdateDTO dto) {
        return episodeService.update(dto);
    }
    @Operation(summary="删除－ 单条",description="按主键删除一条集次记录")
    @DeleteMapping("delete/{id}")
    public boolean delete(@PathVariable("id") Long id) {
        return episodeService.delete(id);
    }
    @Operation(summary="删除－ 批量",description ="按主键批量删除集次记录")
    @DeleteMapping("deleteBatch")
    public boolean deleteBatch(@RequestParam("ids") List<Long> ids) {
        return episodeService.deleteBatch(ids);
    }

    @Operation(summary="修改 - 修改集次视频",description ="修改集次视频")
    @PostMapping("uploadVideo/{id}")
    public Result<String> uploadVideo(MultipartFile videoFile, @PathVariable("id") Long id){
        return episodeService.uploadVideo(videoFile, id);
    }
    @Operation(summary="修改 - 修改集次封面",description ="修改集次封面")
    @PostMapping("uploadVideoCover/{id}")
    public Result<String> uploadVideoCover(MultipartFile videoCoverFile, @PathVariable("id") Long id){
        return episodeService.uploadVideoCover(videoCoverFile, id);
    }
    @Operation(summary="查询－ 报表打印",description ="打印用户相关的报表数据")
    @GetMapping("excel")
    public void excel(HttpServletResponse response) {
        EasyExcelUtil.download(response,
                        ML.Episode.EXCEL_FILE_NAME,
                        ML.Episode.EXCEL_SHEET_NAME,
                        EpisodeExcelDTO.class,
                episodeService.excel());
    }

}
